const app = getApp();

Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    index: 0,
    opinion_list: ['使用反馈','功能建议','其他'],
    opinion_type: '使用反馈',
    opinion_cont: '',
  },

  onShow:function(){
    let _this = this;
    _this.getUserInfo();
  },

  //获取个人信息
  getUserInfo:function(){
    let _this = this;
    wx.showLoading({
      title: '加载中',
    })
    app._post('api/member/getUserInfo', {}, function(result) {
      wx.hideLoading({})
      if(result.code == 200){
        _this.setData({
          is_login:true,
        })
      }else{
        wx.navigateTo({
          url: '../auth/auth'
        })
      }
    });
  },

  /*表单提交*/
  sub_form: function() {
    let _this = this,
      opinion_type = _this.data.opinion_type, //留言类别
      opinion_cont = _this.data.opinion_cont; //留言内容
      console.log(opinion_cont);

    if(opinion_cont == ''){
      wx.showToast({
        title: '请输入留言内容',
        icon: 'none',
        duration: 1500
      })
      return false;
    }

    app._post('api/member/sub_suggestion',
      {
        opinion_type:opinion_type,
        opinion_cont:opinion_cont,
      }, 
    function(result) {
      if(result.code == 200){
        wx.showToast({
          title: result.msg,
          icon: 'success',
          duration: 1500
        })
        setTimeout(function () {
          wx.reLaunch({
            url:'/pages/user/index'
          })
        }, 1500)
      }else{
        wx.showToast({
          title: result.msg,
          icon: 'none',
          duration: 1500
        })
      }
    }, false, function() {
      // 解除禁用
      _this.setData({
        disabled: false
      });
    });
  },

  //下拉框选择
  PickerChange(e) {
    let _this = this,
      opinion_list = _this.data.opinion_list,
      index = e.detail.value;
    _this.setData({
      index: index,
      opinion_type:opinion_list[index]
    })
  },
  
  //输入框
  textareaAInput(e) {
    this.setData({
      opinion_cont: e.detail.value
    })
  },
})